#include "gc.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

typedef itk::ImageFileReader<GrayImage> GrayReader;
typedef itk::ImageFileWriter<GrayImage> GrayWriter;

void convert (const char* inputImagePath, const char* outputImagePath)
{
  GrayReader::Pointer reader = GrayReader::New();
  reader->SetFileName(inputImagePath);
  GrayWriter::Pointer writer = GrayWriter::New();
  writer->SetInput(reader->GetOutput());
  writer->SetFileName(outputImagePath);
  writer->Update();
}

int main (int argc, char* argv[]) 
{
  int argNo = 1;
  const char* inputImageTemplate = argv[argNo++];
  const char* outputImageTemplate = argv[argNo++];
  int startSliceNo = atoi(argv[argNo++]);
  int endSliceNo = atoi(argv[argNo++]);
  for (int sliceNo = startSliceNo; sliceNo <= endSliceNo; sliceNo++) {
    char ifn[200];
    char ofn[200];
    sprintf(ifn, inputImageTemplate, sliceNo);
    sprintf(ofn, outputImageTemplate, sliceNo);
    convert(ifn, ofn);
  }
  return 0;
}
